package com.mogist.hqc.view;

import android.content.Context;
import android.support.v4.widget.NestedScrollView;
import android.util.AttributeSet;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.View;

/**
 * 作用：外层竖向ScrollView,里层横向ScrollView滑动冲突的解决方法
 * 作者：赵小白 email:vvtale@gmail.com  
 * 修改人：
 * 修改时间：
 * 修改备注：
 */
public class CustomNestedScrollView extends NestedScrollView
{
	private GestureDetector mGestureDetector;

	View.OnTouchListener mGestureListener;

	@SuppressWarnings("deprecation")
	public CustomNestedScrollView(Context context, AttributeSet attrs)
	{

		super(context, attrs);

		mGestureDetector = new GestureDetector(new YScrollDetector());

		setFadingEdgeLength(0);
	}

	//通过手势判断，来判断是否拦截触摸事件。
	@Override public boolean onInterceptTouchEvent(MotionEvent ev)
	{
		return super.onInterceptTouchEvent(ev) && mGestureDetector.onTouchEvent(ev);
	}

	class YScrollDetector extends GestureDetector.SimpleOnGestureListener
	{

		@Override
		public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY)
		{
			if(Math.abs(distanceY) > Math.abs(distanceX))
			{
				return true;
			}
			return false;
		}
	}
}